#pragma once
#include "UICommon.h"
#include "RealWndUI.h"

class CCommonWnd : public CWindowWnd
			    , public INotifyUI
{
public:
	CCommonWnd();
	virtual ~CCommonWnd();
	UINT GetClassStyle() const { return CS_DBLCLKS; };

public:
	CPaintManagerUI m_pm;

protected:
	void OnFinalMessage(HWND /*hWnd*/) { delete this; };

	virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

	BEGIN_DUINOTIFY_MAP()
		ON_DUINOTIFY_POINTER("click", m_pMinBtn, OnMinButtonClicked)
		ON_DUINOTIFY_POINTER("click", m_pMaxBtn, OnMaxButtonClicked)
		ON_DUINOTIFY_POINTER("click", m_pRestoreBtn, OnRestoreButtonClicked)
		ON_DUINOTIFY_POINTER("click", m_pCloseBtn, OnCloseButtonClicked)
	END_DUINOTIFY_MAP()

	void OnMinButtonClicked(TNotifyUI& msg);
	void OnMaxButtonClicked(TNotifyUI& msg);
	void OnRestoreButtonClicked(TNotifyUI& msg);
	void OnCloseButtonClicked(TNotifyUI& msg);

	virtual void Init();
	LRESULT PreMessageHandler(const LPMSG pMsg, bool& bHandled);

private:
	CButtonUI* m_pCloseBtn;
	CButtonUI* m_pMaxBtn;
	CButtonUI* m_pRestoreBtn;
	CButtonUI* m_pMinBtn;
};
